package com.sl.au.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.sl.au.entity.BusinesssellerBaseInfo;
import com.sl.au.entity.Evaluate;;

public interface EvaluateRepository extends JpaRepository<Evaluate, String>{
	
	@Query("select a from Evaluate a where a.businesssellerBaseInfo.id=?1")
	Evaluate getInfoByBusinessseller(String id);
	
//	@Query("select a from Evaluate a where a.businesssellerBaseInfo.managementPerson.name like %?1% or a.evaluateLevel.title like %?1% or a.businesssellerBaseInfo.shopName like %?1%")
//	Page<Evaluate> getByKey(String key,Pageable pageable);

	@Query("select a from Evaluate a where a.businesssellerBaseInfo.managementPerson.name like %?1% or a.businesssellerBaseInfo.shopName like %?1%")
	Page<Evaluate> getByKey(String key,Pageable pageable);

	@Query("select a from Evaluate a , Account ac where a.businesssellerBaseInfo.managementPerson.id = ac.user.id and ac.role.id = ?2 and (a.businesssellerBaseInfo.managementPerson.name like %?1% or a.businesssellerBaseInfo.shopName like %?1%)")
	Page<Evaluate> getByKey(String key,String role,Pageable pageable);

	@Query("select count(a) from Evaluate a , Account ac where a.businesssellerBaseInfo.managementPerson.id = ac.user.id and ac.role.id = ?2 and (a.businesssellerBaseInfo.managementPerson.name like %?1% or a.businesssellerBaseInfo.shopName like %?1%)")
	int getCountByKey(String key,String role);

	@Query("select a from Evaluate a , Account ac where a.businesssellerBaseInfo.managementPerson.id = ac.user.id and ac.role.id = ?1 ")
	Page<Evaluate> findAll(String role,Pageable pageable);

	@Query("select count(a) from Evaluate a , Account ac where a.businesssellerBaseInfo.managementPerson.id = ac.user.id and ac.role.id = ?1 ")
	int findCountAll(String role);
}
